#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Cell {
  int x, y, d;
  bool operator<(Cell a) const {
    if (d != a.d)
      return d < a.d;
    else if (x != a.x)
      return x < a.x;
    else
      return y < a.y;
  }
} c[N << 2];
int vis[N << 2], tot;
void init() {
  for (int i = 0, d = 0; i < 50000; ++d, tot = i * 4) {
    rep(x, 0, d) {
      int y = d - x;
      int dis = x * 3 + y * 3 + 2;
      c[i * 4 + 1] = Cell{x * 3 + 1, y * 3 + 1, dis};
      c[i * 4 + 2] = Cell{x * 3 + 1, y * 3 + 2, dis + 1};
      c[i * 4 + 3] = Cell{x * 3 + 2, y * 3 + 1, dis + 1};
      c[i * 4 + 4] = Cell{x * 3 + 2, y * 3 + 2, dis + 4};
      i++;
    }
  }
  sort(c + 1, c + tot + 1);
}
int a[N];
void find(int t, int& i) {
  if (t == 0) {
    do {
      ++i;
    } while (vis[i] || c[i].x % 3 != 1 || c[i].y % 3 != 1);
  } else {
    do {
      ++i;
    } while (vis[i]);
  }
}
void solve() {
  rep(i, 1, n * 4) vis[i] = 0;  // clear state
  int id[2] = {0, 0};
  rep(i, 1, n) {
    find(a[i], id[a[i]]);
    int x = id[a[i]];
    vis[x] = 1;
    cout << c[x].x << ' ' << c[x].y << endl;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    solve();
  }
  return 0;
}